package com.sinosoft.dsp.platform.components.portal.input;

import com.sinosoft.builder.templates.concept.TagElementType;
import com.sinosoft.dsp.system.utils.Const;

public class SinoDefaultSearchControlBean {

	public static final String CONTROL_TYPE_NORMAL = "normal";

	public static final String CONTROL_TYPE_CUSTOM = "custom";

	public static final String CONTROL_TYPE_SPECIAL_SUBMIT = "submit";

	private String elementId;

	private TagElementType type;

	private boolean display;

	public String getControlType() {
		if (type != null && type.getAction() != null) {
			if (!Const.isEmpty(type.getAction().getMethodName())) {
				if (Const.isEmpty(type.getAction().getActionClassName())) {
					return type.getAction().getMethodName();
				} else {
					return CONTROL_TYPE_CUSTOM;
				}
			}
		}
		return CONTROL_TYPE_NORMAL;
	}

	public SinoDefaultSearchControlBean(TagElementType type) {
		this.setElementId(type.getId()).setDisplay(type.isIsDisplay()).setType(
				type);
	}

	public String getElementId() {
		return elementId;
	}

	public SinoDefaultSearchControlBean setElementId(String elementId) {
		this.elementId = elementId;
		return this;
	}

	public TagElementType getType() {
		return type;
	}

	public SinoDefaultSearchControlBean setType(TagElementType type) {
		this.type = type;
		return this;
	}

	public boolean isDisplay() {
		return display;
	}

	public SinoDefaultSearchControlBean setDisplay(boolean display) {
		this.display = display;
		return this;
	}

	public String getOnclick() {
		if (type.getAction() != null) {
			return Const.NVL(type.getAction().getOnclick(), "");
		}
		return "";
	}

	public String getOncomplete() {
		if (type.getAction() != null) {
			return Const.NVL(type.getAction().getOncomplete(), "");
		}
		return "";
	}

	public String getOnstart() {
		if (type.getAction() != null) {
			return Const.NVL(type.getAction().getOnstart(), "");
		}
		return "";
	}

	public String getUpdate() {
		if (type.getAction() != null) {
			return type.getAction().getUpdate();
		}
		return null;
	}

	public boolean isIsAjaxSubmit() {
		if (type.getAction() != null) {
			return type.getAction().isIsAjaxSubmit();
		}
		return true;
	}

	public String getActionClassName() {
		if (type.getAction() != null) {
			return Const.NVL(type.getAction().getActionClassName(), "");
		}
		return "";
	}

	public String getMethodName() {
		if (type.getAction() != null) {
			return Const.NVL(type.getAction().getMethodName(), "");
		}
		return "";
	}

}
